<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" :model="form" :label-col="{ style: { width: '180px' } }">
        <a-row :gutter="24">
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="公司名称">
              <a-input placeholder="请输入" v-model="form.companyName" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="公司法人">
              <a-input placeholder="请输入" v-model="form.legalPerson" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="公司地址">
              <a-input placeholder="请输入" v-model="form.address" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="工商编号">
              <a-input placeholder="请输入" v-model="form.commercialNum" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="公司联系人">
              <a-input placeholder="请输入" v-model="form.contacts" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="联系方式">
              <a-input placeholder="请输入" v-model="form.contactInformation" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="客服电话">
              <a-input placeholder="请输入" v-model="form.serviceTelephone" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="客服微信">
              <a-input placeholder="请输入" v-model="form.serviceWechat" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="银行卡户主">
              <a-input placeholder="请输入" v-model="form.cardOwner" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="户主身份证">
              <a-input placeholder="请输入" v-model="form.ownerId" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="银行名称">
              <a-input placeholder="请输入" v-model="form.bankName" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="银行卡帐号">
              <a-input placeholder="请输入" v-model="form.account" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="微信小程序openid">
              <a-input placeholder="请输入" v-model="form.wechatMiniappOpenid" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="微信小程序密钥">
              <a-input placeholder="请输入" v-model="form.wechatMiniappKey" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="支付body名称">
              <a-input placeholder="请输入" v-model="form.paymentBody" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="微信商户号">
              <a-input placeholder="请输入" v-model="form.wechatMerchantNum" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="微信商户号密钥v2">
              <a-input placeholder="请输入" v-model="form.wechatMerchantKeyV2" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="微信商户号密钥v3">
              <a-input placeholder="请输入" v-model="form.wechatMerchantKeyV3" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="支付宝小程序openid">
              <a-input placeholder="请输入" v-model="form.alipayMiniappAppid" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="Ali（payAccessKeyId）">
              <a-input placeholder="请输入" v-model="form.alipayAccessKeyId" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="Ali（payAccessKeySecret）">
              <a-input placeholder="请输入" v-model="form.alipayAccessKeySecret" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="微信公众号openid">
              <a-input placeholder="请输入" v-model="form.wechatOfficialAccountOpenid" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="微信公众号密钥">
              <a-input placeholder="请输入" v-model="form.wechatOfficialAccountKey" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="微信服务号openid">
              <a-input placeholder="请输入" v-model="form.wechatServiceAccountOpenid" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="微信支付分服务号">
              <a-input placeholder="请输入" v-model="form.wechatPayAccount" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="商户后台api证书序列号">
              <a-input placeholder="请输入" v-model="form.backgroundCertificateNum" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="支付宝AES_KEY">
              <a-input placeholder="请输入" v-model="form.alipayAesKey" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="短信签名">
              <a-input placeholder="请输入" v-model="form.smsSignature" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="短信模版(登录验证)">
              <a-input placeholder="请输入" v-model="form.smdTemplateLogin" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="短信模版(修改密码)">
              <a-input placeholder="请输入" v-model="form.cardOwner" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="短信模版(其他)">
              <a-input placeholder="请输入" v-model="form.smdTemplateOther" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="公司类别">
              <j-dict-select-tag
                allowClear
                v-model="form.companyType"
                :disabled="isDetails"
                placeholder="请选择"
                dictCode="companyType"
              />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="成立时间">
              <a-date-picker
                class="per100"
                v-model="form.establishmentTime"
                :disabled="isDetails"
                valueFormat="YYYY-MM-DD"
              />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="公司状态">
              <j-dict-select-tag
                allowClear
                v-model="form.status"
                :disabled="isDetails"
                placeholder="请选择"
                dictCode="companyStatus"
              />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="12">
            <a-form-item label="总公司返点(%)">
              <a-input placeholder="请输入" v-model="form.rebate" :disabled="isDetails" />
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="24" :xl="24">
            <a-form-item label=" " :colon="false">
              <a-button class="mr10" type="primary" @click="onSubmit" v-if="!isDetails">提交</a-button>
              <a-button @click="closeCurrent()">返回</a-button>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>
  </a-card>
</template>

<script>
import Api from '@/api/CompanyManage/CompanyManage'
import { httpAction, getAction } from '@/api/manage'

export default {
  name: 'CompanyUpdateUpdate',
  inject: ['closeCurrent'],
  data() {
    return {
      form: {
        id: 0,
        companyName: '', // 公司名称
        legalPerson: '', // 公司法人
        address: '', // 公司地址
        commercialNum: '', // 工商编号
        contacts: '', // 公司联系人
        contactInformation: '', // 联系方式
        serviceTelephone: '', // 客服电话
        serviceWechat: '', // 客服微信
        cardOwner: '', // 银行卡户主
        ownerId: '', // 户主身份证
        bankName: '', // 银行名称
        account: '', // 银行卡帐号
        wechatMiniappOpenid: '', // 微信小程序openid
        wechatMiniappKey: '', // 微信小程序密钥
        paymentBody: '', // 支付body名称
        wechatMerchantNum: '', // 微信商户号
        wechatMerchantKeyV2: '', // 微信商户号密钥v2
        wechatMerchantKeyV3: '', // 微信商户号密钥v3
        alipayMiniappAppid: '', // 支付宝小程序openid
        alipayAccessKeyId: '', // Ali（payAccessKeyId）
        alipayAccessKeySecret: '', // Ali（payAccessKeySecret）
        wechatOfficialAccountOpenid: '', // 微信公众号openid
        wechatOfficialAccountKey: '', // 微信公众号密钥
        wechatServiceAccountOpenid: '', // 微信服务号openid
        wechatPayAccount: '', // 微信支付分服务号
        backgroundCertificateNum: '', // 商户后台api证书序列号
        alipayAesKey: '', // 支付宝AES_KEY
        smsSignature: '', // 短信签名
        smdTemplateLogin: '', // 短信模版(登录验证)
        smdTemplateChangePwd: '', // 短信模版(修改密码)
        smdTemplateOther: '', // 短信模版(其他)
        companyType: '', // 公司类别
        establishmentTime: '', // 成立时间
        status: '', // 公司状态
        rebate: '' // 总公司返点(%)
      },
      loading: false,
      isDetails: false
    }
  },
  mounted() {
    if (this.$route.query.details) {
      this.isDetails = true
    }
    if (this.$route.params.id !== 'add') {
      this.getDetails()
    }
  },
  methods: {
    // 获取详情
    getDetails() {
      getAction(Api.queryId, { id: this.$route.params.id })
        .then(res => {
          if (res.code === 200) {
            this.form = res.result
          } else {
            this.$message.error(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    },

    // 提交
    onSubmit() {
      let url = Api.add
      let method = 'post'
      if (this.form.id > 0) {
        url = Api.edit
        method = 'put'
      }
      this.loading = true
      httpAction(url, this.form, method)
        .then(res => {
          if (res.code === 200) {
            this.$message.success(res.message)
            this.closeCurrent()
          } else {
            this.$message.error(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    }
  }
}
</script>

<style scoped></style>

